home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 312_01 / read.me < prev    next >
Text File  |  1990-04-21  |  8KB  |  162 lines

  1.                               Make-Maker
  2.  
  3.                               Jim Yehle
  4.  
  5.                               Sep 28, 89
  6.  
  7.  
  8. The 'make' utility is a real time-saver, as everybody who's used it knows.
  9. But as projects grow and the list of #included files gets complex, the
  10. management of make-files can turn into a real headache.  MAKEMAKE was
  11. created to relieve you of this burden.
  12.  
  13. It's obvious how to construct a make-file once you know 1) all of the object
  14. files which your linker uses to make an executable file, and 2) all of
  15. the source files that each of those object files depends on.  This includes
  16. not only the primary source file, but all files #included (along with 
  17. nested inclusions) by that source file.  Knowing these things, generation
  18. and maintenance of a make-file is a purely mechanical process, whose tedium
  19. is relieved somewhat by features offered by the make utility (such as macro
  20. definitions and implied rules).
  21.  
  22. If it's a mechanical process, why can't it be automated? you ask.  Ah, you're
  23. way ahead of me.  Cincdep.awk is a program which looks into a C source file
  24. and extracts all (even nested) #include files, then builds a dependency list
  25. which is a component of a make-file.  Another program wraps around the single-
  26. file cincdep process to invoke it for each constituent file, and to build
  27. the primary target file's (i.e. executable file's) dependency list.  This
  28. upper-level program takes as its input a linker-configuration file.  Parsing
  29. the idiosyncracies of your linker's syntax will have to be left as an exercise
  30. for the reader.  So far I've built make-makers for Borland's Turbo Linker and
  31. Intel's iRMX binder;  they are called tlr2mak.awk and cf2mak.awk respectively,
  32. after "Turbo Link Response" (using XXXX.TLR files) and "Configure" (using
  33. XXXX.CF files).
  34.  
  35. You don't need to be limited to C for your only programming language.  Other 
  36. dependency generators can be written to find included files according to
  37. the syntax of other languages.  I have included dependency scanner programs
  38. for two other languages, Intel's 80x86 assembler (aincdep.awk) and PL/M
  39. compiler (pincdep.awk).  The make-maker programs are easily extended to
  40. support multiple languages.
  41.  
  42. I realize that this code is not written in C.  However, it is for parsing
  43. C code.  Doubtless many C Users' Group members are UNIX users or have
  44. some other access to awk interpreters.  Unfortunately, CUG's bawk cannot
  45. be used on this code, since it is not a true awk.
  46.  
  47. I have recently put together an object-file extractor which works with
  48. library-building files.  The librarian is Intel's LIB286 for their iRMX
  49. operating system, but the principle could be adapted to other librarians
  50. such as Borland's TLIB.  LIB286 is run with input redirected from what I
  51. call a Library-Input (.LBI) file.  It contains all the ADD commands needed
  52. to build the library from scratch, then save it and exit.  With TLIB, this
  53. .LBI file could become a batch file which first deletes your custom library
  54. and then calls TLIB once for each object file to be added, using the "+"
  55. (add object file) operation.  (Restricting the batch file to one object file
  56. per TLIB invocation makes the awk parsing easier.)  I have included the awk
  57. program LBI2MAK.AWK as an example.
  58.  
  59.  
  60. The assumed output form uses UNIX make's syntax.  Other make-like utilities
  61. use the same general game plan, so quirks are pretty easy to handle.  For
  62. example, MicroSoft's "make" wants the primary target dependency list last,
  63. rather that first, since it treats it just like the rest of the dependency
  64. lists.  SoftFocus' SNAKE won't even work with non-implied compile-command
  65. rules, so you'll have to supply a rules file and force the compile-line
  66. to be blank (by specifying an empty compile-command, and asking that no
  67. components of the source-file name be used in the compile line).  Snake's
  68. exception is the link command, which can be stated directly.  
  69.  
  70. Niceties:  reads the linker's configuration file directly.  There's no
  71. special file you need to maintain for the dependency generator which keeps
  72. parallel information (and which you're likely to forget to update when 
  73. you make changes to the link-configuration file).
  74. Only a simple make utility is called for.  Maybe I'll write one.  The only
  75. functions required of it are that it scan a single dependency list at a time
  76. (which has but one member left of the colon) and look at files' timestamps.
  77. It doesn't even need to process the command; it can just spit out a list of
  78. them into a batch file which can get executed later.
  79.  
  80. Note: you can take all of the debug stuff out.  It may speed things up, but
  81. I would be surprised.  Most of the execution time comes from opening and
  82. reading files, and from repeated executions of the AWK interpreter.  (Copying
  83. the interpreter to a RAM drive and executing it from there probably has the
  84. most significant effect on speed.  If you're blessed with DOS, that is.)
  85. The make-making process can get slow because of all of the file I/O and the
  86. slow speed of awk interpreters, but it's probably not something you'll need
  87. to do very frequently.
  88.  
  89. This code takes advantage of the 1985 enhancements to the original (1977) awk
  90. language.  (My reference was "The AWK Programming Language," by Alfred V. Aho,
  91. Brian W. Kernighan and Peter J. Weinberger, published by Addison-Wesley.)
  92. Factors such as recursively-called user-defined functions preclude converting
  93. this code to run on the older awk.  Sorry!
  94.  
  95.  
  96.  
  97. Example batch files (for MS/PC-DOS):
  98.  
  99. In all of these examples, I use my own directory conventions.  I have a source-
  100. file root directory for each (major) project or development environment, with
  101. a subdirectory under it for each language, and an INC directory under each one
  102. of those for include-files.  I move the SUBST pseudo-drive S: about to projects'
  103. root directories.  I also use drives L:, O: and M: for the directories where 
  104. linker input files, object files, and makefiles live.
  105.  
  106. The batch command CALL, in versions of DOS earlier than 3.3, can be replaced
  107. wherever they appear, with COMMAND /C.
  108.  
  109. The makefiles which these batch files produce have the executable-file's name
  110. with an extension .MAK.  This requires running MAKE with the -f option to
  111. replace "makefile" as the default makefile name.
  112.  
  113.  
  114. rem TLR2MAK.BAT
  115. rem 
  116. rem  Produces a makefile, given a Turbo Link response (.TLR) file as input
  117. rem
  118. awk -f s:\awk\tlr2mak.awk l:\%1.tlr outfile=m:\%1.mak lc=tlink lcf=n >temp.bat
  119. call temp.bat
  120.  
  121.  
  122. rem TL.BAT
  123. rem
  124. rem  Run Turbo Linker with ALL arguments taken from a TLR file
  125. rem
  126. tlink @l:\%1.tlr
  127.  
  128.  
  129. Here's an example of the a turbo link response file BAWK.TLR:
  130.  
  131. /c /d /x+
  132. \turboc\lib\c0s o:\bawk o:\bawkdo o:\bawkact o:\bawkpat o:\bawksym
  133. o:\bawk
  134.  
  135. \turboc\lib\emu \turboc\lib\maths \turboc\lib\graphics \turboc\lib\cs
  136.  
  137.  
  138.  
  139. Contents of the disk:
  140.  
  141.    read.me         This explanatory text file
  142.    cincdep.awk     C dependency generator
  143.    tlr2mak.awk     Turbo Link Response file object-file extractor
  144.    cf2mak.awk      Intel Linker (binder) configuration file object-file extractor
  145.    lbi2mak.awk     Intel librarian input-file object-file extractor
  146.    aincdep.awk     Intel 80x86 assembly language dependency generator
  147.    pincdep.awk     Intel PL/M dependency generator
  148.  
  149.  
  150.  
  151.  
  152. AUTHOR'S RELEASE
  153.  
  154.  
  155. It is my intention that this code be used by members of my profession to
  156. ease some of the tedium of software development.  It is against my wishes
  157. that this material be sold for somebody else's monetary gain.  Feel free
  158. to distribute it by any means you like, charging only direct costs such as
  159. for the medium and postage.  I hereby release this material into the public
  160. domain for the C Users' to distribute.
  161.  
  162.